package com.bosssoft.hr.javase;

import java.util.LinkedList;
import java.util.List;

public class MyQueue<T> implements Queue <T>{

    public int len;



    public MyQueue() {
        this.len = Integer.MAX_VALUE;
    }
    public MyQueue(int len) {
        this.len = len;
    }

    public boolean add(T data) throws Exception {
        List<T> qu = new LinkedList<T>();
        if (qu.add(data)==true) {
            return true;
        } else {
            throw new Exception("加入失败");
        }
    }

    public boolean offer(T data) {
        List<T> qu = new LinkedList<T>();
        if (qu.add(data)==true) {
            return true;
        } else {
            return false;
        }
    }

    public T remove() throws Exception {
        List<T> qu = new LinkedList<T>();
        qu.add((T) new Student(1,"wang"));
        if (qu.size() == 0) {
            throw new Exception("队列为空");
        }
        return qu.remove(0);
    }

    public T poll() { //移除队首
        List<T> qu = new LinkedList<T>();
        qu.add((T) new Student(1,"wang"));
        return qu.size() == 0 ? null : qu.remove(0);
    }

    public T element() { //取得队首元素
        List<T> qu = new LinkedList<T>();
        qu.add((T) new Student(1,"wang"));
        return  qu.get(0);
    }

    public T peek() throws Exception { // 取得队首元素如果队列为空则抛出异常
        List<T> qu = new LinkedList<T>();
        qu.add((T) new Student(1,"wang"));
        if (qu.size() == 0) {
            throw new Exception("队列为空");
        }
        return qu.remove(0);
    }


    }



